import Vue from 'vue'
import VueRouter from 'vue-router'
import Main from '@/page/layout.vue'
import { Message } from 'element-ui'

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Main,
    redirect: "/home/index",
    children: [
      {
        path:'/home/index',
        component: () => import(/* webpackChunkName: "home" */ '../views/Home/index.vue')
      }
    ]
  },
  {
    path: '/MailLoading',
    name: 'MailLoading',
    component: () => import(/* webpackChunkName: "MailLoading" */ '../views/MailLoading/index.vue'),
  },
  {
    path: '/userHome',
    name: 'userHome',
    redirect: '/userhomes',
    // redirect: "/userHome/index",
    component: () => import(/* webpackChunkName: "userHome" */ '../views/userHome/index.vue'),
    children:[
      {
        path: '/userhomes',
        component: () => import(/* webpackChunkName: "userHome" */ '../views/userHome/components/index.vue')
      },
      {
        path: '/baseUserlist',
        component: () => import(/* webpackChunkName: "userHome" */ '../views/userHome/baselist/index')
      },
      {
        path: '/setSafety',
        component: () => import(/* webpackChunkName: "userHome" */ '../views/userHome/setSafety/index')
      },
      {
        path: '/personalDetails',
        component: () => import(/* webpackChunkName: "userHome" */ '../views/userHome/personalDetails/index')
      },
      {
        path: '/authentications',
        component: () => import(/* webpackChunkName: "userHome" */ '../views/userHome/authentication/index.vue')
      },
      // {
      //   path: '/auth',
      //   component: () => import(/* webpackChunkName: "userHome" */ '../views/userHome/authentication/index.vue')
      // },
      {
        path: '/subAccount',
        component: () => import(/* webpackChunkName: "userHome" */ '../views/userHome/subAccount/index')
      },
      {
        path: '/userss',
        component: () => import(/* webpackChunkName: "userHome" */ '../views/userHome/userss/index')
      },
      {
        path: '/staff',
        name: 'staff',
        component: () => import(/* webpackChunkName: "userHome" */ '../views/userHome/staff/staff.vue')
      },
      {
        path: '/paid',
        name: 'paid',
        component: () => import(/* webpackChunkName: "userHome" */ '../views/userHome/paid/paid.vue')
      },
      // {
      //   path: '/message',
      //   name: 'message',
      //   component: () => import(/* webpackChunkName: "userHome" */ '../views/userHome/message/message.vue')
      // },
      {
        path: '/company',
        name: 'company',
        component: () => import(/* webpackChunkName: "userHome" */ '@/views/userHome/company/index.vue')
      },
      {
        path: '/myContract',
        name: 'myContract',
        component: () => import(/* webpackChunkName: "userHome" */ '@/views/userHome/myContract/index.vue')
      },
     
      {
        path: '/certification',
        name: 'certification',
        component: () => import(/* webpackChunkName: "userHome" */ '@/views/userHome/certification/certification.vue')
      },
      {//企业详情
        path: '/certificationlist',
        name: 'certificationlist',
        component: () => import(/* webpackChunkName: "userHome" */ '@/views/userHome/certification/creaitcationlist.vue')
      },
      {// 我的订单
        path: '/order',
        name:'order',
        component: () => import(/* webpackChunkName: "userHome" */ '../views/userHome/order/index.vue')
      }
     
      
    ]
  },
  {
    path: '/login',
    name: 'Login',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "login" */ '../views/Login/index.vue')
  },

  {
    path: '/reg',
    name: 'Reg',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "login" */ '../views/Login/reg.vue')
  },
  {
    path: '/parkService',
    name: 'parkService',
    component: Main,
    redirect: "/parkService/index",
    children:[
      {
        path: '/parkService/index',
        component: () => import(/* webpackChunkName: "BasicServicesPark" */ '../views/BasicServicesPark/index.vue')
      },
      {// 缴费
        path: '/parkService/paycost',
        name:'paycost',
        component: () => import(/* webpackChunkName: "BasicServicesPark" */ '../views/BasicServicesPark/paycost/paycost.vue')
      },
      {// 缴费下的订单详情
        path: '/parkService/orderDetails',
        name:'orderDetails',
        component: () => import(/* webpackChunkName: "BasicServicesPark" */ '../views/BasicServicesPark/paycost/orderDetails.vue')
      },
      {// 支付信息
        path: '/parkService/payInfo',
        name:'payInfo',
        component: () => import(/* webpackChunkName: "BasicServicesPark" */ '../views/BasicServicesPark/paycost/payInfo.vue')
      },
      {// 支付成功后的页面
        path: '/parkService/success',
        name:'success',
        component: () => import(/* webpackChunkName: "BasicServicesPark" */ '../views/BasicServicesPark/paycost/success.vue')
      },
      {
        path: '/parkService/houseRent',
        name: 'houseRent',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "BasicServicesPark" */ '../views/BasicServicesPark/HouseRent.vue')
      },
      {
        path: '/parkService/vehicleAccess',
        name: 'vehicleAccess',
        component: () => import(/* webpackChunkName: "BasicServicesPark" */ '../views/BasicServicesPark/vehicleAccess/index.vue')
      },
      {
        path: 'parkService/vehicleAccess/add',
        name: 'addVehicleAccess',
        component: () => import(/* webpackChunkName: "BasicServicesPark" */ '../views/BasicServicesPark/vehicleAccess/add.vue')
      },
      
      {
        path: '/orderInformation',
        name: 'orderInformation',
        component: () => import(/* webpackChunkName: "BasicServicesPark" */ '../views/BasicServicesPark/orderInformation.vue')
      },
      {
        path: '/payment',
        name: 'payment',
        component: () => import(/* webpackChunkName: "BasicServicesPark" */ '../views/BasicServicesPark/payment.vue')
      },
      {
        path: '/parkService/pay',
        name: 'pay',
        component: () => import(/* webpackChunkName: "BasicServicesPark" */ '../views/BasicServicesPark/pay.vue')
      },
      {
        path: '/warehousing',
        name: 'warehousing',
        component: () => import(/* webpackChunkName: "BasicServicesPark" */ '../views/BasicServicesPark/warehousing.vue')
        // component: () => import(/* webpackChunkName: "login" */ '../views/Login/reg.vue')
      },
      // -----------------------------------------------------
      {
        path: '/parkService/index',
        component: () => import(/* webpackChunkName: "about" */ '../views/BasicServicesPark/index.vue')
      },
      {
        path: '/parkService/houseRent',
        name: 'houseRent',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/BasicServicesPark/HouseRent.vue')
      },
      {
        path: '/orderInformation',
        name: 'orderInformation',
        component: () => import(/* webpackChunkName: "about" */ '../views/BasicServicesPark/orderInformation.vue')
      },
      {
        path: '/payment',
        name: 'payment',
        component: () => import(/* webpackChunkName: "about" */ '../views/BasicServicesPark/payment.vue')
      },
      {
        path: '/warehousing',
        name: 'warehousing',
        component: () => import(/* webpackChunkName: "about" */ '../views/BasicServicesPark/warehousing.vue')
        // component: () => import(/* webpackChunkName: "login" */ '../views/Login/reg.vue')
      },{
        path: "/meetingOrder",
        name: "meetingOrder",
        component: () =>
            import(/* webpackChunkName: "page" */ "../views/xiexin/meetingReservation/meetingOrder")
      },
      {
        path: "/newMeetingOrder",
        name: "newMeetingOrder",
        component: () =>
            import(/* webpackChunkName: "page" */ "../views/xiexin/meetingReservation/newOrder")
      },
      {
        path: "/activityOrder",
        name: "activityOrder",
        component: () =>
            import(/* webpackChunkName: "page" */ "../views/xiexin/activityYardReservation/activityOrder")
      },
      {
        path: "/newActivityOrder",
        name: "newActivityOrder",
        component: () =>
            import(/* webpackChunkName: "page" */ "../views/xiexin/activityYardReservation/newOrder")
      },
      {
        path: "/repairList",
        name: "repairList",
        component: () =>
            import(/* webpackChunkName: "page" */ "../views/xiexin/repairReport/repairList")
      },
      {
        path: "/addRepairReport",
        name: "addRepairReport",
        component: () =>
            import(/* webpackChunkName: "page" */ "../views/xiexin/repairReport/addRepairReport")
      },
      {
        path: "/reportDetail",
        name: "reportDetail",
        component: () =>
            import(/* webpackChunkName: "page" */ "../views/xiexin/repairReport/ReportDetail")
      }
      
    ]
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    // component: () => import(/* webpackChunkName: "login" */ '../views/Login/reg.vue')
  },
  {
    path: '/about',
    name: 'About',
    component: Main,
    redirect: "/about/index",
    children: [
      {
        path:'/about/index',
        component: () => import(/* webpackChunkName: "About" */ '../views/About/index.vue')
      }
    ]
  },
 
  {// 合同详情
    path: '/myContractlist',
    name: 'mycontractlist',
    component: () => import(/* webpackChunkName: "userHome" */ '../views/userHome/myContract/list.vue')
  },
    {// 我的订单详情
      path: '/orderist',
      name:'orderlist',
      component: () => import(/* webpackChunkName: "userHome" */ '../views/userHome/order/orderlist.vue')
    },
  
]

const router = new VueRouter({
  routes
})
//路由守卫
router.beforeEach((to, from, next) => {
  if (to.path === '/login'||to.path === '/reg') { return next() }
  const tokenStr =JSON.parse(window.localStorage.getItem('XIE_XIN'))
  if (!tokenStr) {
    Message.error('身份验证过期，请重新登录')
    return next('/login')
  }
  next()
})

export default router
